/*
===========================================================================
Copyright (C) 2005 Sarunas

This file is part of MyPIRC source code.

DisksDB source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

DisksDB source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with DisksDB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
using System;

namespace MyIRC
{
	public class IrcUser : BaseObject, IUser
	{
		public event EventHandlerNickChanged NickChanged;

		protected string nick = null;
		protected string ident = null;
		protected string hostName = null;
		protected string fullName = null;
		protected string realName = null;

		public IrcUser(IrcClient server, string fullName) : base(server)
		{
			this.fullName = fullName;

			string v1 = "";
			string v2 = "";
			string v3 = "";

			string[] words = fullName.Split(new char[3] {':', '!', '@'});

			if (words.Length > 1) v1 = words[1];
			if (words.Length > 2) v2 = words[2];
			if (words.Length > 3) v3 = words[3];

			if (words.Length == 1)
			{
				v1 = words[0];
			}

			this.SetData(v1, v2, v3);
		}

		public IrcUser(IrcClient server, string nick, string ident, string hostName) : base(server)
		{
			this.fullName = nick + "!" + ident + "@" + hostName;

			this.SetData(nick, ident, hostName);
		}

		private void SetData(string nick, string ident, string hostName)
		{
			this.nick = nick;
			this.ident = ident;
			this.hostName = hostName;
		}

		public virtual string Nick
		{
			get
			{
				return this.nick;
			}
			set
			{
			}
		}

		public virtual string Ident
		{
			get
			{
				return this.ident;
			}
			set
			{
			}
		}

		public virtual string HostName
		{
			get
			{
				return this.hostName;
			}
		}

		public virtual string RealName
		{
			get
			{
				return this.realName;
			}
			set
			{
			}
		}

		public virtual string FullId
		{
			get
			{
				return this.fullName;
			}
		}

		public virtual void OnNickChanged(string newNick)
		{
			string oldNick = this.nick;

			this.nick = newNick;
			this.fullName = this.nick + "!" + this.ident + "@" + this.hostName;

			if (null != this.NickChanged)
			{
				this.NickChanged(this.server, this, oldNick, newNick);
			}
		}
	}
}
